<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('审核列表列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">

        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('business:carPackageAudit:edit')}]];
    var removeFlag = [[${@permission.hasPermi('business:carPackageAudit:remove')}]];
    var statusDatas = [[${@dict.getType('cpa_status')}]];
    var prefix = ctx + "business/carPackageAudit";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "审核列表",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '当前节点审核人',
                    visible: false
                },
                {
                    field: 'serviceItem.name',
                    title: '套餐名称',
                },
                {
                    field: 'serviceItem.discountPrice',
                    title: '套餐价格',
                },
                {
                    field: 'createByName',
                    title: '创建人'
                },
                {
                    field: 'createTime',
                    title: '创建时间'
                },
                {
                    field: 'taskName',
                    title: '当前任务名称'
                },
                {
                    field: 'status',
                    title: '审核状态',
                    formatter: function (value, row, index) {
                        console.log(value);
                        //statusDatas:获取到套餐审核的所有状态选项
                        //value:当前记录的值
                        //内部是拿到当前记录的值,在所有的状态选项中进行遍历,如果当前记录的值==选项中的值,把中文信息返回
                        return $.table.selectDictLabel(statusDatas, value)
                    }
                },
                {
                    field: 'auditors',
                    title: '当前审核人'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        console.log(row);
                        /*
                            auditors: "[\"熊长青\"]"
                            createBy: "1"
                            createByName: "管理员"
                            createTime: "2021-07-23 21:04:09"
                            id: 5
                            instanceId: "45001"
                            params: {}
                            processDefinitionId: "carPackageAudit:17:32503"
                            serviceItem: {createTime: "2021-05-18 10:31:13", params: {…}, id: 4, name: "车身美容", originalPrice: 2990, …}
                            serviceItemInfo: "{\"auditStatus\":1,\"carPackage\":1,\"createTime\":1621305073000,\"discountPrice\":1888.00,\"id\":4,\"info\":\"包括高压洗车，去除沥青、焦油等污物，上蜡增艳与镜面处理，新车开蜡，钢圈、轮胎、保险杠翻新与底盘防腐涂胶处理\",\"modifyTime\":1627041492000,\"name\":\"车身美容\",\"originalPrice\":2990.00,\"params\":{},\"saleStatus\":0,\"serviceCatalog\":1,\"version\":6}"
                            status: 0
                            taskId: "45007"
                            taskName: "店长审批"
                         */
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="showHistoryDialog(\'' + row.instanceId + '\')"><i class="fa fa-list"></i> 审批历史</a> ');
                        actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="showProcessImgDialog(\'' + row.id + '\')"><i class="fa fa-image"></i> 进度查看</a> ');
                        if (row.taskName.indexOf('已结束') === -1) {
                            actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="cancelApply(\'' + row.instanceId + '\',\'' + row.createBy + '\')"><i class="fa fa-times"></i> 撤销</a> ');
                        }
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function showProcessImgDialog(id) {
        var url = prefix + '/processImg/' + id;
        $.modal.open("查看流程图", url);
    }
    function cancelApply(instanceId) {
        $.modal.confirm("您确定要撤销吗?",function () {
            var url = prefix + '/cancelApply';
            var  data = {"instanceId":instanceId};
            $.operate.submit(url,"post","json",data);
        });
    }
</script>
</body>
</html>